import requests
import json
import urllib.parse


def start(**kwargs):
    # 将用户信息对象转换为JSON字符串，然后进行URL编码
    user_info = kwargs.get('data').get('user')
    user_info_json = json.dumps(user_info, ensure_ascii=False)
    user_info_encoded = urllib.parse.quote(user_info_json)

    cookies = {
        'tempTokenKey': kwargs.get('data').get('refreshToken'),
        'userInfoKey': user_info_encoded,  # 使用URL编码后的字符串
        'pwdState': 'true',
        'inspurRoleKey': 'ROLE_AREA',
    }

    headers = {
        'Host': 'gzmh.zwfw.guizhou.gov.cn',
        'sec-ch-ua-platform': '"Windows"',
        'Authorization': kwargs.get('data').get('token'),
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36',
        'Accept': 'application/json, text/plain, */*',
        'sec-ch-ua': '"Not;A=Brand";v="99", "Google Chrome";v="139", "Chromium";v="139"',
        'sec-ch-ua-mobile': '?0',
        'Origin': 'https://gzmh.zwfw.guizhou.gov.cn',
        'Sec-Fetch-Site': 'same-origin',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Dest': 'empty',
        'Referer': 'https://gzmh.zwfw.guizhou.gov.cn/login/',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Content-Type': 'application/x-www-form-urlencoded',
    }

    params = {
        'userId': '9E1059C9335D4C7CB8DC7400D03AECFB',
    }

    response = requests.post(
        'https://gzmh.zwfw.guizhou.gov.cn/zhsl/service/getWindowListByUserId',
        params=params,
        cookies=cookies,
        headers=headers,
    )

    cookies['windowId'] = response.json()['data'][0]['id']
    return cookies
